#include "src/parsing/token.h"

#define T(name, string, precedence) #name,
const char* const Token::name_[NUM_TOKENS] = { TOKEN_LIST(T, T) };
#undef T

#define T(name, string, precedence) string,
const char* const Token::string_[NUM_TOKENS] = { TOKEN_LIST(T, T) };
#undef T

constexpr uint8_t length(const char* str) {
    return str ? static_cast<uint8_t>(strlen(str)) : 0;
}

#define T(name, string, precedence) length(string),
const uint8_t Token::string_length_[NUM_TOKENS] = { TOKEN_LIST(T, T) };
#undef T

#define T1(name, string, precedence)    \
    ((Token::name == Token::IN) ? 0 : precedence),
#define T2(name, string, precedence) precedence,

const int8_t Token::precedence_[2][NUM_TOKENS] = { { TOKEN_LIST(T1, T1) }, { TOKEN_LIST(T2, T2) } };

#undef T2
#undef T1

#define KT(a, b, c)                     \
    IsPropertyNameBits::encode(Token::IsAnyIdentifier(a) || a == ESCAPED_KEYWORD),
#define KK(a, b, c)                     \
    IsKeywordBits::encode(true) | IsPropertyNameBits::encode(true),
const uint8_t Token::token_flags[] = { TOKEN_LIST(KT, KK) };
#undef KT
#undef KK